package com.wyp168.serviceedu.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wyp168.commonutils.R;
import com.wyp168.serviceedu.entity.EduCourse;
import com.wyp168.serviceedu.entity.EduTeacher;
import com.wyp168.serviceedu.service.EduCourseService;
import com.wyp168.serviceedu.service.EduTeacherService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "前台讲师控制器")
@RestController
@CrossOrigin
@Slf4j
@RequestMapping("serviceedu/teacherfront")
public class TeacherFrontController {

    @Autowired
    private EduTeacherService teacherService;

    @Autowired
    private EduCourseService courseService;

    @GetMapping("teacherPage/{pageNo}/{pageSize}")
    public R getTeacherPage(@PathVariable Integer pageNo,@PathVariable Integer pageSize) {

        //调用讲师接口，查询讲师信息并分页
        Map<String,Object> teacherMap = teacherService.getTeacherPage(pageNo, pageSize);

        return R.ok().data(teacherMap);
    }


    //讲师详情
    @GetMapping("getTeacherFrontInfo/{teacherId}")
    public R getTeacherFrontInfo(@PathVariable String teacherId) {
        //根据讲师id查询讲师的基本信息
        EduTeacher teacherInfo = teacherService.getById(teacherId);

        //根据讲师id
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",teacherId);
        List<EduCourse> eduTeacherCourse = courseService.list(wrapper);
        return R.ok().data("teacherInfo",teacherInfo).data("courseList",eduTeacherCourse);
    }

}




